﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_stat_attendance
	/// </summary>
	public partial class oa_stat_attendance
	{
		public oa_stat_attendance()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("stat_id", "oa_stat_attendance"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int stat_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_stat_attendance");
			strSql.Append(" where stat_id=@stat_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@stat_id", MySqlDbType.Int32)
};
			parameters[0].Value = stat_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_stat_attendance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_stat_attendance(");
			strSql.Append("stat_date,ought_count,actual_count,absence_count,later_count,sick_count,causal_count)");
			strSql.Append(" values (");
			strSql.Append("@stat_date,@ought_count,@actual_count,@absence_count,@later_count,@sick_count,@causal_count)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@stat_date", MySqlDbType.DateTime),
					new MySqlParameter("@ought_count", MySqlDbType.Int32,11),
					new MySqlParameter("@actual_count", MySqlDbType.Int32,11),
					new MySqlParameter("@absence_count", MySqlDbType.Int32,11),
					new MySqlParameter("@later_count", MySqlDbType.Int32,11),
					new MySqlParameter("@sick_count", MySqlDbType.Int32,11),
					new MySqlParameter("@causal_count", MySqlDbType.Int32,11)};
			parameters[0].Value = model.stat_date;
			parameters[1].Value = model.ought_count;
			parameters[2].Value = model.actual_count;
			parameters[3].Value = model.absence_count;
			parameters[4].Value = model.later_count;
			parameters[5].Value = model.sick_count;
			parameters[6].Value = model.causal_count;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_stat_attendance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_stat_attendance set ");
			strSql.Append("stat_date=@stat_date,");
			strSql.Append("ought_count=@ought_count,");
			strSql.Append("actual_count=@actual_count,");
			strSql.Append("absence_count=@absence_count,");
			strSql.Append("later_count=@later_count,");
			strSql.Append("sick_count=@sick_count,");
			strSql.Append("causal_count=@causal_count");
			strSql.Append(" where stat_id=@stat_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@stat_date", MySqlDbType.DateTime),
					new MySqlParameter("@ought_count", MySqlDbType.Int32,11),
					new MySqlParameter("@actual_count", MySqlDbType.Int32,11),
					new MySqlParameter("@absence_count", MySqlDbType.Int32,11),
					new MySqlParameter("@later_count", MySqlDbType.Int32,11),
					new MySqlParameter("@sick_count", MySqlDbType.Int32,11),
					new MySqlParameter("@causal_count", MySqlDbType.Int32,11),
					new MySqlParameter("@stat_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.stat_date;
			parameters[1].Value = model.ought_count;
			parameters[2].Value = model.actual_count;
			parameters[3].Value = model.absence_count;
			parameters[4].Value = model.later_count;
			parameters[5].Value = model.sick_count;
			parameters[6].Value = model.causal_count;
			parameters[7].Value = model.stat_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int stat_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_stat_attendance ");
			strSql.Append(" where stat_id=@stat_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@stat_id", MySqlDbType.Int32)
};
			parameters[0].Value = stat_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string stat_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_stat_attendance ");
			strSql.Append(" where stat_id in ("+stat_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_stat_attendance GetModel(int stat_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select stat_id,stat_date,ought_count,actual_count,absence_count,later_count,sick_count,causal_count from oa_stat_attendance ");
			strSql.Append(" where stat_id=@stat_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@stat_id", MySqlDbType.Int32)
};
			parameters[0].Value = stat_id;

			becom.Model.oa_stat_attendance model=new becom.Model.oa_stat_attendance();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["stat_id"]!=null && ds.Tables[0].Rows[0]["stat_id"].ToString()!="")
				{
					model.stat_id=int.Parse(ds.Tables[0].Rows[0]["stat_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["stat_date"]!=null && ds.Tables[0].Rows[0]["stat_date"].ToString()!="")
				{
					model.stat_date=DateTime.Parse(ds.Tables[0].Rows[0]["stat_date"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ought_count"]!=null && ds.Tables[0].Rows[0]["ought_count"].ToString()!="")
				{
					model.ought_count=int.Parse(ds.Tables[0].Rows[0]["ought_count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["actual_count"]!=null && ds.Tables[0].Rows[0]["actual_count"].ToString()!="")
				{
					model.actual_count=int.Parse(ds.Tables[0].Rows[0]["actual_count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["absence_count"]!=null && ds.Tables[0].Rows[0]["absence_count"].ToString()!="")
				{
					model.absence_count=int.Parse(ds.Tables[0].Rows[0]["absence_count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["later_count"]!=null && ds.Tables[0].Rows[0]["later_count"].ToString()!="")
				{
					model.later_count=int.Parse(ds.Tables[0].Rows[0]["later_count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["sick_count"]!=null && ds.Tables[0].Rows[0]["sick_count"].ToString()!="")
				{
					model.sick_count=int.Parse(ds.Tables[0].Rows[0]["sick_count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["causal_count"]!=null && ds.Tables[0].Rows[0]["causal_count"].ToString()!="")
				{
					model.causal_count=int.Parse(ds.Tables[0].Rows[0]["causal_count"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select stat_id,stat_date,ought_count,actual_count,absence_count,later_count,sick_count,causal_count ");
			strSql.Append(" FROM oa_stat_attendance ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_stat_attendance";
			parameters[1].Value = "stat_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

